// 植物类--[向日葵0,最慢单炮1,火种2，戴头盔火炮3]
let plantsType = [
    {type:0,num:18,name:'sunflower',path:'images/plants/sunflower/idle/idle_00.png'},
{type:1,num:14,name:'repeater',path:'images/plants/repeater/idle/idle_00.png'},
{type:2,num:12,name:'idle_00',path:'images/plants/gatlingpea/idle/idle_00.png'},
{type:3,num:1,name:'nature_fire',path:'images/nature_fire.png'}] //植物帧动画图片分别有多少帧
let fire = null
class Plants {
    constructor(obj){
        let s = {
            x:obj.x,
            y:obj.y,
            id:obj.id,
            type:obj.type, //植物种类，0为向日葵
        }
        Object.assign(this,s)
    }
    draw(){
        let sunflowers = new Array(18)
        let self = this,
        img = document.createElement('img'),             // 创建元素
        container = document.getElementById('app'), // 父级元素容器
        id = self.id,                                 // 当前角色 ID
        top = self.y,
        left = self.x
        // 添加阳关元素
        if(self.type === 0){
            img.src = 'images/plants/sunflower/idle/idle_00.png'
        }
        if(self.type === 1){
            img.src = 'images/plants/repeater/idle/idle_00.png'
        }
        if(self.type === 2){
            img.src = 'images/plants/gatlingpea/idle/idle_00.png'
        }
        if(self.type === 3){
            img.src = 'images/nature_fire.png'
            img.style.width = '70px'
            img.style.height = 'auto'
        }
        
        img.className += plantsType[self.type].name
        img.style.position = 'absolute'
        img.style.top = top + 'px'
        img.style.left = left + 'px'
        img.style.zIndex = 9
        container.appendChild(img)
        let i = 0
        let src = img.src
        let plant = {}
        plantsType.forEach(item=>{
            item.type === self.type && (plant = item)
            return
        })
        this['plant'+id] = setInterval(()=>{
            i++
            i<10&&(i='0'+i)
            img.src = src.replace(/00/g,i)
            i>=plant.num&&(i=0)
        },50)
        timers.push(this['plant'+id])
        if(self.type===3) {
            fire = document.querySelectorAll('.nature_fire')
            return
        }
        new Bullets({x:self.x,y:self.y,id:id,type:1}).draw()
    }
}